<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../css/detail.css">
  </head>
  <body style="background:white">
    <header>
        <h3>帖子详情</h3>
    </header>
    <h4></h4>
    <div class="content"></div>
      <div class="Image"></div>
      <div class="haha">精彩评论</div>
      <div class="comments"></div>

  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript" src="../../script/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="../../script/main.js"></script>

<script>


     apiready=function(){
       var aid = $api.getStorage("aid");
       var UIChatBox=api.require("UIChatBox");
       var id = api.pageParam.id;
       var page=0;
       var faker=false;
       getacticle();
       getcomment(id,page,faker);
         function getacticle(){
           var url='/api/public-msgs/'+id;
           var functionRet=function(ret){
                 $("h4").html(ret.title);
                 $(".content").html(ret.content);
                 for (var i = 0; i < ret.imageList.length; i++) {
                      $(".Image").append('<img src='+"http://"+ret.imageList[i].replace(/["'"]/g,"")+'>');
                 }
           }
           var functionErr=function(err){
             return false
           }
           get(url,functionRet,functionErr);
         }
       UIChatBox.open({
           placeholder: '',
           maxRows: 4,
           emotionPath: 'widget://image/emotion',
           texts: {
               sendBtn:{
                   title:'send'
               }
           },
           styles: {
               inputBar: {
                   borderColor: '#d9d9d9',
                   bgColor: '#f2f2f2'
               },
               inputBox: {
                   borderColor: '#B3B3B3',
                   bgColor: '#FFFFFF'
               },
               emotionBtn: {
                   normalImg: 'widget://res/img/chatBox_face1.png'
               },
               sendBtn: {
                   titleColor: '#FFFFFF',
                   bg: ' #1296db' ,
                   activeBg: 'blue',
                   titleSize: 14
               }
           },
           extras: {
               titleSize: 10,
               titleColor: '#a3a3a3',
               btns: [{
                   title: '图片',
                   normalImg: 'widget://res/img/chatBox_album1.png',
                   activeImg: 'widget://res/img/chatBox_album2.png'
               },{
                   title: '拍照',
                   normalImg: 'widget://res/img/chatBox_cam1.png',
                   activeImg: 'widget://res/img/chatBox_cam2.png'
               }]
           }
       }, function(ret, err){
           if( ret ){
                //alert(JSON.stringify( ret.eventType ));
                if (ret.eventType=="send") {
                     if (ret.msg) {
                           sendcomments(ret.msg);

                     }else {
                       alert("请输入内容！")
                     }
                }
           }else{
                //alert( JSON.stringify( err ) );
           }
       });

            function sendcomments(msg){
                 var url='/api/public-msg-comments';
                 var data={
                     "aid":aid,
                     "content":msg,
                     "publicMsgId":id
                 };
                 var functionRet=function(ret){
                   $(".comments").html(" ");
                   faker=true;
                   getcomment(id,page,faker);
                 }
                 var functionErr=function(){
                   return false
                 }
                     post(url,data,functionRet,functionErr);
                      UIChatBox.closeKeyboard();


            }

              function getcomment(id,page,size){
                    var url='/api/public-msg-comments?publicMsgId='+id;
                    var functionRet=function(ret){
                               if (ret.length) {
                                 for (var i = 0; i < ret.length; i++) {
                                   $(".comments").append('<div class="comment"><div class="reply_c"><img src='+ret[i].userHeaderImageUrl+'><span class="commentName">'+ret[i].userName+'</span></div><div class="commentFont"><span>'+ret[i].publicMsgComment.content+'</span></div><span class="reply" commentsAid-id='+ret[i].publicMsgComment.aid+' commentsAid-name='+ret[i].userName+'>回复</span><span class="delete" comment-id='+ret[i].publicMsgComment.id+' commentsAid-id='+ret[i].publicMsgComment.aid+'>删除</span><div class="ct"></div></div>');

                                 }
                               }
                    }
                    var functionErr=function(err){
                      return false
                    }
                    get(url,functionRet,functionErr);

              }


               function deletecomment(id){
                 var url='/api/public-msg-comments/'+id;
                 var data="";
                 var functionRet=function(){
                                //console.log(111);
                 }
                 var functionErr=function(){

                              $(".comments").html("");
                              getcomment(api.pageParam.id,page,faker);


                 }
                 deleteData(url,data,functionRet,functionErr);
               }

               $(".comments").on("click",".delete",function(){
                      if (aid==$(this).attr('commentsAid-id')) {

                               deletecomment($(this).attr('comment-id'));
                      }
               })
     }
</script>
</html>
